#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>

const char* maya[] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"};

const char* tz[] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};

int whichMonth(char *a)
{
  assert(a != NULL);
  for(int i = 0;i<20;i++)
    {
      if(strcmp(maya[i],a) == 0)  
        {
          return i;
        }
    }
  return -1;
}

#ifndef FILEIO
#define main1008 main
#endif

int main1008(int argc,char **argv) 
{ 

#ifdef FILEIO
  freopen("1008in.txt","r",stdin); 
  freopen("1008out.txt","w",stdout); 
#endif

  int N;
  

  scanf("%d\n",&N);
  printf("%d\n",N);
  int day,year;
#define SIZE 10  
  char a[SIZE];

  for(int i = 0;i<N;i++)
    {
      memset(a,0,SIZE*sizeof(char));
      scanf("%d. %s %d",&day,a,&year);
      //printf("%d. %s %d\n",day,a,year);
      int month = whichMonth(a); 
	  assert(month!=-1);
      int total = 365*year + day  + month*20;
      int tzYear = total/260;
      int tzNumber = (total%260)%13+1;
      int tzDay = (total%260)%20; 
	  printf("%d %s %d\n",tzNumber,tz[tzDay],tzYear);
    }
  
  

#ifdef FILEIO
  fclose(stdin);
  fclose(stdout);
#endif  
  
  return 0; 
}
